﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Common;

namespace SERS.ExamRoom
{
    public partial class ExamTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string json = GetAllExam();
            List<ExamRoomList> list = new List<ExamRoomList>();
            if (!string.IsNullOrEmpty(json))
            {
                hidExams.Value = json;
                list = JsonConvert.DeserializeObject<List<ExamRoomList>>(json);
                if (list != null && list.Count > 0)
                {
                    string ids = "";

                    StringBuilder kecheng1Html = new StringBuilder("<dt class=\"class_category class_category1\" id=\"monikaochang\" style=\"cursor: pointer;\"><img src=\"images/sers/class_nav_item_icon1.jpg\" />模拟考场</dt>");
                    for (int i = 0; i < list.Count; i++)
                    {
                        kecheng1Html.Append("<dd name=\"moniti\" pid=\"" + list[i].id + "\" style=\"cursor: pointer;\" onclick=\"GetNewExam(" + list[i].id + ", 1);\">■ 模拟题" + list[i].id + "</dd>");
                        if (i == 0)
                        {
                            ids = list[i].id.ToString();
                            hidExamRoomID.Value = list[0].id.ToString();
                        }
                        else
                        {
                            ids += "|" + list[i].id;
                        }
                    }
                    kecheng1.InnerHtml = kecheng1Html.ToString();
                    hidExamIdList.Value = ids;
                    hidExamMaxId.Value = list.OrderByDescending(p => p.id).FirstOrDefault().id.ToString();
                }
            }
        }

        /// <summary>
        /// 获取所有模拟题库
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetAllExam()
        {
            Service client = new Service();
            string _path = Server.MapPath("Exam\\Exam.txt");
            string str = client.ReaderTxt(_path);
            return str;
        }
    }
}